<html>
<head><meta charset="utf-8"><title>Library level Undefined Behavior · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Library.20level.20Undefined.20Behavior.html">Library level Undefined Behavior</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="193572683"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Library%20level%20Undefined%20Behavior/near/193572683" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Elichai Turkel <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Library.20level.20Undefined.20Behavior.html#193572683">(Apr 10 2020 at 14:10)</a>:</h4>
<p>Hi,<br>
Let's say I have a library that provides <code>MyBool</code> <a href="https://play.rust-lang.org/?gist=04a65599a5fe5df5ed56264384015fe6" title="https://play.rust-lang.org/?gist=04a65599a5fe5df5ed56264384015fe6">https://play.rust-lang.org/?gist=04a65599a5fe5df5ed56264384015fe6</a></p>
<p>Is this a correct/idiomatic use of unsafe? there will be no language UB or memory unsafety if you use it, but it will violate the library API contract.</p>



<a name="193574255"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Library%20level%20Undefined%20Behavior/near/193574255" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Library.20level.20Undefined.20Behavior.html#193574255">(Apr 10 2020 at 14:26)</a>:</h4>
<p><span class="user-mention" data-user-id="249222">@Elichai Turkel</span>  I would do <code>enum Something { Yes, No }</code></p>



<a name="193574373"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Library%20level%20Undefined%20Behavior/near/193574373" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Elichai Turkel <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Library.20level.20Undefined.20Behavior.html#193574373">(Apr 10 2020 at 14:27)</a>:</h4>
<p><span class="user-mention" data-user-id="126931">@centril</span> You're right. I was trying to show a simple example, but I'm sure you can imagine a library that assumes some struct has only certain values, and my question is if the <code>unchecked</code> version of the constructor should be unsafe or not</p>



<a name="193574785"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Library%20level%20Undefined%20Behavior/near/193574785" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Library.20level.20Undefined.20Behavior.html#193574785">(Apr 10 2020 at 14:31)</a>:</h4>
<p><span class="user-mention" data-user-id="249222">@Elichai Turkel</span>  only if the invariants that need to be upheld can cause UB if not</p>



<a name="193574817"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Library%20level%20Undefined%20Behavior/near/193574817" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Elichai Turkel <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Library.20level.20Undefined.20Behavior.html#193574817">(Apr 10 2020 at 14:31)</a>:</h4>
<p>UB at a language level or also at a library level?</p>



<a name="193575976"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Library%20level%20Undefined%20Behavior/near/193575976" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Library.20level.20Undefined.20Behavior.html#193575976">(Apr 10 2020 at 14:42)</a>:</h4>
<p><span class="user-mention" data-user-id="249222">@Elichai Turkel</span> UB only exists at the "language level"; it occurs if you violate the operational semantics of the language causing the abstract machine to throw an <code>Err(_)</code> (in the Miri sense)</p>



<a name="193577820"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Library%20level%20Undefined%20Behavior/near/193577820" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mark Drobnak <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Library.20level.20Undefined.20Behavior.html#193577820">(Apr 10 2020 at 14:58)</a>:</h4>
<p>It might be better to panic if the setter receives a value which is unexpected (not 0 or 1 in this case). Panicking is idiomatic when the issue is "unrecoverable", such as indexing out of bounds (<code>array[100]</code> panics, <code>array.get(100)</code> still returns an <code>Option</code>).<br>
<a href="https://doc.rust-lang.org/book/ch09-03-to-panic-or-not-to-panic.html" title="https://doc.rust-lang.org/book/ch09-03-to-panic-or-not-to-panic.html">https://doc.rust-lang.org/book/ch09-03-to-panic-or-not-to-panic.html</a></p>



<a name="193582108"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Library%20level%20Undefined%20Behavior/near/193582108" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Library.20level.20Undefined.20Behavior.html#193582108">(Apr 10 2020 at 15:33)</a>:</h4>
<p>A library can certainly consider some of its invariants relevant for safety (and thus reserve the right to cause UB if the invariant is broken) even if it does not <em>currently</em> do anything that could lead to UB if the invariant is broken. However, <code>unsafe</code> should not be "diluted" by wantonly using it for things that aren't and never will be relevant to the prevention of UB. So unless you have a specific reason to expect you'll need an invariant like this, it's probably best to be cautious and not introduce <code>unsafe</code> just for fun.</p>



<a name="193591576"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Library%20level%20Undefined%20Behavior/near/193591576" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Library.20level.20Undefined.20Behavior.html#193591576">(Apr 10 2020 at 16:58)</a>:</h4>
<p><span class="user-mention silent" data-user-id="126931">centril</span> <a href="#narrow/stream/122651-general/topic/Library.20level.20Undefined.20Behavior/near/193575976" title="#narrow/stream/122651-general/topic/Library.20level.20Undefined.20Behavior/near/193575976">said</a>:</p>
<blockquote>
<p><span class="user-mention silent" data-user-id="249222">Elichai Turkel</span> UB only exists at the "language level"; it occurs if you violate the operational semantics of the language causing the abstract machine to throw an <code>Err(_)</code> (in the Miri sense)</p>
</blockquote>
<p>to be fair, even Rust libstd is not entirely precise about this use of UB though. And UB is a common enough term in library APIs that I am not sure if it is worth to fight the idea of "library UB". think, e.g., of our allocator traits.</p>



<a name="193591646"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Library%20level%20Undefined%20Behavior/near/193591646" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Library.20level.20Undefined.20Behavior.html#193591646">(Apr 10 2020 at 16:59)</a>:</h4>
<p><span class="user-mention" data-user-id="249222">@Elichai Turkel</span> I would say if you plan to have some code, elsewhere, rely on your invariant for safety/UB-freedom, then this is totally idiomatic.</p>



<a name="193591738"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Library%20level%20Undefined%20Behavior/near/193591738" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Library.20level.20Undefined.20Behavior.html#193591738">(Apr 10 2020 at 17:00)</a>:</h4>
<p>generally, if your type's <a href="https://www.ralfj.de/blog/2018/08/22/two-kinds-of-invariants.html" title="https://www.ralfj.de/blog/2018/08/22/two-kinds-of-invariants.html">safety invariant</a> could be violated by a method, I'd use <code>unsafe</code> for that</p>



<a name="193593109"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Library%20level%20Undefined%20Behavior/near/193593109" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Library.20level.20Undefined.20Behavior.html#193593109">(Apr 10 2020 at 17:11)</a>:</h4>
<p><span class="user-mention" data-user-id="120791">@RalfJ</span> well "library UI" meaning "Misuse of this library can result in R-AM UB right now or later" is something I'm behind, but using it for other things feels confusing</p>



<a name="193593225"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Library%20level%20Undefined%20Behavior/near/193593225" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Library.20level.20Undefined.20Behavior.html#193593225">(Apr 10 2020 at 17:12)</a>:</h4>
<p>I think it is fine to use it for non-Rust abstract machine UB, too, though, right? Like this is the principle behind things like FFI being unsafe</p>



<a name="193593264"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Library%20level%20Undefined%20Behavior/near/193593264" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Library.20level.20Undefined.20Behavior.html#193593264">(Apr 10 2020 at 17:12)</a>:</h4>
<p><span class="user-mention" data-user-id="116122">@simulacrum</span>  I believe we also accepted the notion of "target UB" in UCG</p>



<a name="193593281"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Library%20level%20Undefined%20Behavior/near/193593281" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Library.20level.20Undefined.20Behavior.html#193593281">(Apr 10 2020 at 17:12)</a>:</h4>
<p>which covers that aspect</p>



<a name="193593336"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Library%20level%20Undefined%20Behavior/near/193593336" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Library.20level.20Undefined.20Behavior.html#193593336">(Apr 10 2020 at 17:13)</a>:</h4>
<p>ah, not sure I follow that -- I meant specifically that the set of non-confusing UB being larger than just that of R-AM is what I'd expect</p>



<a name="193593359"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Library%20level%20Undefined%20Behavior/near/193593359" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Library.20level.20Undefined.20Behavior.html#193593359">(Apr 10 2020 at 17:13)</a>:</h4>
<p><span class="user-mention" data-user-id="116122">@simulacrum</span>  yeah I read your message again and I think I read it wrong</p>



<a name="193593426"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Library%20level%20Undefined%20Behavior/near/193593426" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Library.20level.20Undefined.20Behavior.html#193593426">(Apr 10 2020 at 17:14)</a>:</h4>
<p>some other abstract machine integrated with Rust also seems reasonable for "UB"</p>



<a name="193593471"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Library%20level%20Undefined%20Behavior/near/193593471" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Library.20level.20Undefined.20Behavior.html#193593471">(Apr 10 2020 at 17:14)</a>:</h4>
<p>E.g. the combined program using C++ and Rust causing either of the abstract machines to have UB</p>



<a name="193593493"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Library%20level%20Undefined%20Behavior/near/193593493" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Library.20level.20Undefined.20Behavior.html#193593493">(Apr 10 2020 at 17:14)</a>:</h4>
<p>probably LLVM UB of some form</p>



<a name="193593524"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Library%20level%20Undefined%20Behavior/near/193593524" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Library.20level.20Undefined.20Behavior.html#193593524">(Apr 10 2020 at 17:15)</a>:</h4>
<p>sure, but I would say that limiting in such a way seems odd</p>



<a name="193593541"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Library%20level%20Undefined%20Behavior/near/193593541" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Library.20level.20Undefined.20Behavior.html#193593541">(Apr 10 2020 at 17:15)</a>:</h4>
<p><span class="user-mention silent" data-user-id="126931">centril</span> <a href="#narrow/stream/122651-general/topic/Library.20level.20Undefined.20Behavior/near/193593109" title="#narrow/stream/122651-general/topic/Library.20level.20Undefined.20Behavior/near/193593109">said</a>:</p>
<blockquote>
<p><span class="user-mention silent" data-user-id="120791">RalfJ</span> well "library UI" meaning "Misuse of this library can result in R-AM UB right now or later" is something I'm behind, but using it for other things feels confusing</p>
</blockquote>
<p>I would say that is exactly what "violating a library's safety invariant" is. That's what safety invariants are for.</p>



<a name="193593584"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Library%20level%20Undefined%20Behavior/near/193593584" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Library.20level.20Undefined.20Behavior.html#193593584">(Apr 10 2020 at 17:15)</a>:</h4>
<p><span class="user-mention" data-user-id="120791">@RalfJ</span> yeah that's how I'd phrase it as well <span aria-label="slight smile" class="emoji emoji-1f642" role="img" title="slight smile">:slight_smile:</span></p>



<a name="193593594"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Library%20level%20Undefined%20Behavior/near/193593594" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Library.20level.20Undefined.20Behavior.html#193593594">(Apr 10 2020 at 17:15)</a>:</h4>
<p>yeah, e.g. it includes putting non-UTF8 data inside string (presuming that String never actually causes R-AM UB due to that)</p>



<a name="193593671"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Library%20level%20Undefined%20Behavior/near/193593671" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Library.20level.20Undefined.20Behavior.html#193593671">(Apr 10 2020 at 17:16)</a>:</h4>
<p><span class="user-mention silent" data-user-id="116122">simulacrum</span> <a href="#narrow/stream/122651-general/topic/Library.20level.20Undefined.20Behavior/near/193593594" title="#narrow/stream/122651-general/topic/Library.20level.20Undefined.20Behavior/near/193593594">said</a>:</p>
<blockquote>
<p>yeah, e.g. it includes putting non-UTF8 data inside string (presuming that String never actually causes R-AM UB due to that)</p>
</blockquote>
<p>exactly. (right now UTF-8 str <a href="https://doc.rust-lang.org/reference/behavior-considered-undefined.html" title="https://doc.rust-lang.org/reference/behavior-considered-undefined.html">is a R-AM condition</a> but I think we should get rid of that.)</p>



<a name="193593676"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Library%20level%20Undefined%20Behavior/near/193593676" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Library.20level.20Undefined.20Behavior.html#193593676">(Apr 10 2020 at 17:16)</a>:</h4>
<p>That is:</p>
<div class="codehilite"><pre><span></span><span class="sd">/// # Safety</span>
</pre></div>


<p>basically</p>



<a name="193593724"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Library%20level%20Undefined%20Behavior/near/193593724" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Library.20level.20Undefined.20Behavior.html#193593724">(Apr 10 2020 at 17:16)</a>:</h4>
<p><span class="user-mention" data-user-id="120791">@RalfJ</span> I thought everyone was agreed it's not a R-AM condition</p>



<a name="193593752"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Library%20level%20Undefined%20Behavior/near/193593752" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Library.20level.20Undefined.20Behavior.html#193593752">(Apr 10 2020 at 17:16)</a>:</h4>
<p>well the reference says it's one^^</p>



<a name="193593759"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Library%20level%20Undefined%20Behavior/near/193593759" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Library.20level.20Undefined.20Behavior.html#193593759">(Apr 10 2020 at 17:16)</a>:</h4>
<p>oh wow</p>



<a name="193593767"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Library%20level%20Undefined%20Behavior/near/193593767" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Library.20level.20Undefined.20Behavior.html#193593767">(Apr 10 2020 at 17:16)</a>:</h4>
<p>so I figured we'd need an RFC to change that</p>



<a name="193593797"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Library%20level%20Undefined%20Behavior/near/193593797" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Library.20level.20Undefined.20Behavior.html#193593797">(Apr 10 2020 at 17:17)</a>:</h4>
<p>that's a pretty weird and unusable form of UB it seems to me</p>



<a name="193593815"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Library%20level%20Undefined%20Behavior/near/193593815" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Library.20level.20Undefined.20Behavior.html#193593815">(Apr 10 2020 at 17:17)</a>:</h4>
<p>what is LLVM going to use that for... heh?</p>



<a name="193593825"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Library%20level%20Undefined%20Behavior/near/193593825" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Library.20level.20Undefined.20Behavior.html#193593825">(Apr 10 2020 at 17:17)</a>:</h4>
<p><em>shrug</em> IIRC I just grandfathered it when editing that page</p>



<a name="193593848"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Library%20level%20Undefined%20Behavior/near/193593848" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Library.20level.20Undefined.20Behavior.html#193593848">(Apr 10 2020 at 17:17)</a>:</h4>
<p><span class="user-mention silent" data-user-id="126931">centril</span> <a href="#narrow/stream/122651-general/topic/Library.20level.20Undefined.20Behavior/near/193593815" title="#narrow/stream/122651-general/topic/Library.20level.20Undefined.20Behavior/near/193593815">said</a>:</p>
<blockquote>
<p>what is LLVM going to use that for... heh?</p>
</blockquote>
<p>I dont know why you bring up LLVM here. MIR is an IR with semantics on its own right. ;)</p>



<a name="193593920"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Library%20level%20Undefined%20Behavior/near/193593920" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Library.20level.20Undefined.20Behavior.html#193593920">(Apr 10 2020 at 17:18)</a>:</h4>
<p><span class="user-mention" data-user-id="120791">@RalfJ</span> sure but many of the UB conditions we have are for some good reason  (e.g. LLVM exploiting it)</p>



<a name="193593939"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Library%20level%20Undefined%20Behavior/near/193593939" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Library.20level.20Undefined.20Behavior.html#193593939">(Apr 10 2020 at 17:18)</a>:</h4>
<p>is this UB condition just a result of confusing safety invariant with UB?</p>



<a name="193593949"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Library%20level%20Undefined%20Behavior/near/193593949" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Library.20level.20Undefined.20Behavior.html#193593949">(Apr 10 2020 at 17:18)</a>:</h4>
<p>I mean we could give LLVM, in theory, the right to optimize the search in UTF-8 data knowing that</p>



<a name="193593955"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Library%20level%20Undefined%20Behavior/near/193593955" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Library.20level.20Undefined.20Behavior.html#193593955">(Apr 10 2020 at 17:18)</a>:</h4>
<p>I think this one exists because "someone added it to the reference when initially writing that page" <span aria-label="rofl" class="emoji emoji-1f923" role="img" title="rofl">:rofl:</span></p>



<a name="193593974"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Library%20level%20Undefined%20Behavior/near/193593974" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Library.20level.20Undefined.20Behavior.html#193593974">(Apr 10 2020 at 17:18)</a>:</h4>
<p><span class="user-mention silent" data-user-id="126931">centril</span> <a href="#narrow/stream/122651-general/topic/Library.20level.20Undefined.20Behavior/near/193593939" title="#narrow/stream/122651-general/topic/Library.20level.20Undefined.20Behavior/near/193593939">said</a>:</p>
<blockquote>
<p>is this UB condition just a result of confusing safety invariant with UB?</p>
</blockquote>
<p>I think so</p>



<a name="193593979"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Library%20level%20Undefined%20Behavior/near/193593979" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Library.20level.20Undefined.20Behavior.html#193593979">(Apr 10 2020 at 17:18)</a>:</h4>
<p>i.e. we really meant "safety invariant" but used the wrong term "accidentally"?</p>



<a name="193594006"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Library%20level%20Undefined%20Behavior/near/193594006" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Library.20level.20Undefined.20Behavior.html#193594006">(Apr 10 2020 at 17:19)</a>:</h4>
<p>but yeah, I think it is just a safety invariant</p>



<a name="193594008"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Library%20level%20Undefined%20Behavior/near/193594008" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Library.20level.20Undefined.20Behavior.html#193594008">(Apr 10 2020 at 17:19)</a>:</h4>
<p>it's older than that term</p>



<a name="193594028"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Library%20level%20Undefined%20Behavior/near/193594028" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Library.20level.20Undefined.20Behavior.html#193594028">(Apr 10 2020 at 17:19)</a>:</h4>
<p>(ah, should be)</p>



<a name="193594051"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Library%20level%20Undefined%20Behavior/near/193594051" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Library.20level.20Undefined.20Behavior.html#193594051">(Apr 10 2020 at 17:19)</a>:</h4>
<p>I think that seems like a reasonable theory about what happened here</p>



<a name="193594140"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Library%20level%20Undefined%20Behavior/near/193594140" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Library.20level.20Undefined.20Behavior.html#193594140">(Apr 10 2020 at 17:20)</a>:</h4>
<p><span class="user-mention" data-user-id="126931">@centril</span> it goes back aaaall the way: <a href="https://doc.rust-lang.org/1.0.0/reference.html#behavior-considered-undefined" title="https://doc.rust-lang.org/1.0.0/reference.html#behavior-considered-undefined">https://doc.rust-lang.org/1.0.0/reference.html#behavior-considered-undefined</a></p>



<a name="193594152"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Library%20level%20Undefined%20Behavior/near/193594152" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Library.20level.20Undefined.20Behavior.html#193594152">(Apr 10 2020 at 17:20)</a>:</h4>
<p><span class="user-mention" data-user-id="120791">@RalfJ</span> hmm... do you want to open a PR to the reference to remove that? If you want an FCP let's do it on an issue or so</p>



<a name="193594185"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Library%20level%20Undefined%20Behavior/near/193594185" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Library.20level.20Undefined.20Behavior.html#193594185">(Apr 10 2020 at 17:20)</a>:</h4>
<p><span class="user-mention silent" data-user-id="126931">centril</span> <a href="#narrow/stream/122651-general/topic/Library.20level.20Undefined.20Behavior/near/193594152" title="#narrow/stream/122651-general/topic/Library.20level.20Undefined.20Behavior/near/193594152">said</a>:</p>
<blockquote>
<p><span class="user-mention silent" data-user-id="120791">RalfJ</span> hmm... do you want to open a PR to the reference to remove that? If you want an FCP let's do it on an issue or so</p>
</blockquote>
<p>so you are saying no RFC needed? you are the process expert, fine for me ;)</p>



<a name="193594192"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Library%20level%20Undefined%20Behavior/near/193594192" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Library.20level.20Undefined.20Behavior.html#193594192">(Apr 10 2020 at 17:20)</a>:</h4>
<p>I'll add doing that to my list</p>



<a name="193594227"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Library%20level%20Undefined%20Behavior/near/193594227" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Library.20level.20Undefined.20Behavior.html#193594227">(Apr 10 2020 at 17:21)</a>:</h4>
<p>That would be a pretty short RFC heh :D</p>



<a name="193594308"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Library%20level%20Undefined%20Behavior/near/193594308" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Library.20level.20Undefined.20Behavior.html#193594308">(Apr 10 2020 at 17:21)</a>:</h4>
<p>if you prefer that format over FCP that's fine by me -- I can't imagine anyone on the team actually thinking it's a part of the validity invariant</p>



<a name="193594388"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Library%20level%20Undefined%20Behavior/near/193594388" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Library.20level.20Undefined.20Behavior.html#193594388">(Apr 10 2020 at 17:22)</a>:</h4>
<p>(of course my imagination is sometimes limited ^^)</p>



<a name="193594393"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Library%20level%20Undefined%20Behavior/near/193594393" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Library.20level.20Undefined.20Behavior.html#193594393">(Apr 10 2020 at 17:22)</a>:</h4>
<p><em>shrug</em> I'm in for both, if FCP works it's less work for me ;)</p>



<a name="193594410"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Library%20level%20Undefined%20Behavior/near/193594410" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Library.20level.20Undefined.20Behavior.html#193594410">(Apr 10 2020 at 17:22)</a>:</h4>
<p>it also seems like it's at least presumably not important for outside consumers?</p>



<a name="193594416"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Library%20level%20Undefined%20Behavior/near/193594416" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Library.20level.20Undefined.20Behavior.html#193594416">(Apr 10 2020 at 17:22)</a>:</h4>
<p>sgtm then ^^</p>



<a name="193594439"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Library%20level%20Undefined%20Behavior/near/193594439" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Library.20level.20Undefined.20Behavior.html#193594439">(Apr 10 2020 at 17:22)</a>:</h4>
<p>in <a href="https://github.com/rust-lang/unsafe-code-guidelines/issues/78" title="https://github.com/rust-lang/unsafe-code-guidelines/issues/78">https://github.com/rust-lang/unsafe-code-guidelines/issues/78</a> everyone also agreed it should be safety, not validity</p>



<a name="193594477"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Library%20level%20Undefined%20Behavior/near/193594477" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Library.20level.20Undefined.20Behavior.html#193594477">(Apr 10 2020 at 17:23)</a>:</h4>
<p><span class="user-mention silent" data-user-id="116122">simulacrum</span> <a href="#narrow/stream/122651-general/topic/Library.20level.20Undefined.20Behavior/near/193594410" title="#narrow/stream/122651-general/topic/Library.20level.20Undefined.20Behavior/near/193594410">said</a>:</p>
<blockquote>
<p>it also seems like it's at least presumably not important for outside consumers?</p>
</blockquote>
<p>it's relevant in the sense that if you create a non-UTF-8 <code>str</code> and dont use it, this makes it UB</p>



<a name="193594485"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Library%20level%20Undefined%20Behavior/near/193594485" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Library.20level.20Undefined.20Behavior.html#193594485">(Apr 10 2020 at 17:23)</a>:</h4>
<p>but if we only have "library UB" then that's actually fine</p>



<a name="193594506"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Library%20level%20Undefined%20Behavior/near/193594506" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Library.20level.20Undefined.20Behavior.html#193594506">(Apr 10 2020 at 17:23)</a>:</h4>
<p>sure, yeah</p>



<a name="193594515"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Library%20level%20Undefined%20Behavior/near/193594515" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Library.20level.20Undefined.20Behavior.html#193594515">(Apr 10 2020 at 17:23)</a>:</h4>
<p>you only start having to worry about this once you call <code>str</code> methods</p>



<a name="193594517"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Library%20level%20Undefined%20Behavior/near/193594517" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Library.20level.20Undefined.20Behavior.html#193594517">(Apr 10 2020 at 17:23)</a>:</h4>
<p>though "using it" is a bit up in the air</p>



<a name="193594586"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Library%20level%20Undefined%20Behavior/near/193594586" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Library.20level.20Undefined.20Behavior.html#193594586">(Apr 10 2020 at 17:24)</a>:</h4>
<p>ah yes</p>



<a name="193594605"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Library%20level%20Undefined%20Behavior/near/193594605" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Library.20level.20Undefined.20Behavior.html#193594605">(Apr 10 2020 at 17:24)</a>:</h4>
<p>so if its a validity invariant then it has to hold even when the value is just <em>constructed</em></p>



<a name="193594634"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Library%20level%20Undefined%20Behavior/near/193594634" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Library.20level.20Undefined.20Behavior.html#193594634">(Apr 10 2020 at 17:24)</a>:</h4>
<p>but if its just a safety invariant then as long as you dont pass it to a foreign method as <code>&amp;str</code>, you are definitely good</p>



<a name="193594644"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Library%20level%20Undefined%20Behavior/near/193594644" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Library.20level.20Undefined.20Behavior.html#193594644">(Apr 10 2020 at 17:24)</a>:</h4>
<p>like, if you only pass it around in your own code at that type</p>



<a name="193594665"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Library%20level%20Undefined%20Behavior/near/193594665" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Library.20level.20Undefined.20Behavior.html#193594665">(Apr 10 2020 at 17:24)</a>:</h4>
<p><span class="user-mention" data-user-id="120791">@RalfJ</span> is the standard library not violating this  validity invariant in a bunch of places?</p>



<a name="193594718"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Library%20level%20Undefined%20Behavior/near/193594718" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Library.20level.20Undefined.20Behavior.html#193594718">(Apr 10 2020 at 17:25)</a>:</h4>
<p>maybe it always works with <code>[u8]</code> internally in those APIs</p>



<a name="193594732"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Library%20level%20Undefined%20Behavior/near/193594732" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Library.20level.20Undefined.20Behavior.html#193594732">(Apr 10 2020 at 17:25)</a>:</h4>
<p>hm, I think std is pretty good about it</p>



<a name="193594935"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Library%20level%20Undefined%20Behavior/near/193594935" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Library.20level.20Undefined.20Behavior.html#193594935">(Apr 10 2020 at 17:27)</a>:</h4>
<p><span class="user-mention silent" data-user-id="116122">simulacrum</span> <a href="#narrow/stream/122651-general/topic/Library.20level.20Undefined.20Behavior/near/193593949" title="#narrow/stream/122651-general/topic/Library.20level.20Undefined.20Behavior/near/193593949">said</a>:</p>
<blockquote>
<p>I mean we could give LLVM, in theory, the right to optimize the search in UTF-8 data knowing that</p>
</blockquote>
<p>Out of curiosity, is there a plausible compiler where this could actually give some noticeable benefits?</p>



<a name="193594954"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Library%20level%20Undefined%20Behavior/near/193594954" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Library.20level.20Undefined.20Behavior.html#193594954">(Apr 10 2020 at 17:27)</a>:</h4>
<p>That's a very speculative question... but well, there it is <span aria-label="slight smile" class="emoji emoji-1f642" role="img" title="slight smile">:slight_smile:</span></p>



<a name="193595240"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Library%20level%20Undefined%20Behavior/near/193595240" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Library.20level.20Undefined.20Behavior.html#193595240">(Apr 10 2020 at 17:29)</a>:</h4>
<p>the UCG discussion makes it a fairly clear "no" I think</p>



<a name="193596015"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Library%20level%20Undefined%20Behavior/near/193596015" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Library.20level.20Undefined.20Behavior.html#193596015">(Apr 10 2020 at 17:36)</a>:</h4>
<p><span class="user-mention silent" data-user-id="126931">centril</span> <a href="#narrow/stream/122651-general/topic/Library.20level.20Undefined.20Behavior/near/193594665" title="#narrow/stream/122651-general/topic/Library.20level.20Undefined.20Behavior/near/193594665">said</a>:</p>
<blockquote>
<p><span class="user-mention silent" data-user-id="120791">RalfJ</span> is the standard library not violating this  validity invariant in a bunch of places?</p>
</blockquote>
<p>no idea...</p>



<a name="193596062"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Library%20level%20Undefined%20Behavior/near/193596062" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Library.20level.20Undefined.20Behavior.html#193596062">(Apr 10 2020 at 17:36)</a>:</h4>
<p><span class="user-mention silent" data-user-id="126931">centril</span> <a href="#narrow/stream/122651-general/topic/Library.20level.20Undefined.20Behavior/near/193594935" title="#narrow/stream/122651-general/topic/Library.20level.20Undefined.20Behavior/near/193594935">said</a>:</p>
<blockquote>
<p><span class="user-mention silent" data-user-id="116122">simulacrum</span> <a href="#narrow/stream/122651-general/topic/Library.20level.20Undefined.20Behavior/near/193593949" title="#narrow/stream/122651-general/topic/Library.20level.20Undefined.20Behavior/near/193593949">said</a>:</p>
<blockquote>
<p>I mean we could give LLVM, in theory, the right to optimize the search in UTF-8 data knowing that</p>
</blockquote>
<p>Out of curiosity, is there a plausible compiler where this could actually give some noticeable benefits?</p>
</blockquote>
<p>that search is in a method though, so this method could conceivably still do <code>unsafe_assume(this_is_utf8)</code> and use the safety invariant to justify the assume</p>



<a name="193596568"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Library%20level%20Undefined%20Behavior/near/193596568" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Library.20level.20Undefined.20Behavior.html#193596568">(Apr 10 2020 at 17:41)</a>:</h4>
<p>true</p>



<a name="193613676"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Library%20level%20Undefined%20Behavior/near/193613676" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Elichai Turkel <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Library.20level.20Undefined.20Behavior.html#193613676">(Apr 10 2020 at 20:25)</a>:</h4>
<p>Hehe, I was thinking of utf8 but didn't want to bring it up because lately it comes up a lot when I talk with <span class="user-mention" data-user-id="120791">@RalfJ</span></p>



<a name="193663582"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Library%20level%20Undefined%20Behavior/near/193663582" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Library.20level.20Undefined.20Behavior.html#193663582">(Apr 11 2020 at 14:42)</a>:</h4>
<p><span class="user-mention" data-user-id="126931">@centril</span> here you go: <a href="https://github.com/rust-lang/reference/pull/792" title="https://github.com/rust-lang/reference/pull/792">https://github.com/rust-lang/reference/pull/792</a></p>



<a name="193672644"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Library%20level%20Undefined%20Behavior/near/193672644" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Library.20level.20Undefined.20Behavior.html#193672644">(Apr 11 2020 at 18:18)</a>:</h4>
<p><span class="user-mention" data-user-id="120791">@RalfJ</span> <span aria-label="slight smile" class="emoji emoji-1f642" role="img" title="slight smile">:slight_smile:</span> FCP as promised: <a href="https://github.com/rust-lang/rust/issues/71033#issuecomment-612481973" title="https://github.com/rust-lang/rust/issues/71033#issuecomment-612481973">https://github.com/rust-lang/rust/issues/71033#issuecomment-612481973</a></p>



<a name="193677580"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Library%20level%20Undefined%20Behavior/near/193677580" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Library.20level.20Undefined.20Behavior.html#193677580">(Apr 11 2020 at 20:17)</a>:</h4>
<p>The Rustonomicon has long put "also anything else your library chooses to call unsafe" as part of what's unsafe.</p>



<a name="193678822"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Library%20level%20Undefined%20Behavior/near/193678822" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> marmeladema <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Library.20level.20Undefined.20Behavior.html#193678822">(Apr 11 2020 at 20:48)</a>:</h4>
<p>(deleted)</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>